package com.wuzihao.reggie.controller;

import com.wuzihao.reggie.common.R;
import com.wuzihao.reggie.entity.ShoppingCart;
import com.wuzihao.reggie.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Autowired
    ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    public R add(@RequestBody ShoppingCart shoppingCart){
        ShoppingCart result = shoppingCartService.add(shoppingCart);

        return R.success(result);
    }

    @GetMapping("/list")
    public R list(){
        List<ShoppingCart> list = shoppingCartService.listShoppingCart();

        return R.success(list);
    }

    @DeleteMapping("/clean")
    public R delete(){
        shoppingCartService.delete();

        return R.success("清除购物车成功");
    }
}
